#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Created on 2010-2-21

@author: neatchenheng
'''

import urllib2

class BasicAuthHandler(object):
    '''
    
    '''
    opener = None
    uri = None
    
    
    
    def __init__(self,uri,user,passwd):
        '''
        uri :
        user :
        passwd :
        '''
        
        auth_handler = urllib2.HTTPBasicAuthHandler()
        auth_handler.add_password(realm='Joker Application',
                                  uri=uri,
                                  user=user,
                                  passwd=passwd)
        self.opener = urllib2.build_opener(auth_handler)
        self.uri = uri
    
    def download(self):
        urllib2.install_opener(self.opener)
        data = urllib2.urlopen(self.uri)
        print data.geturl()
        print data.info()
        
    
        

